package com.hex.ds.hdtp.core.web.script.transfer.controller;

import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.script.transfer.dto.request.ScriptConvertOptLogRequestDto;
import com.hex.ds.hdtp.core.app.script.transfer.service.IScriptConvertOptLogService;
import com.hex.ds.hdtp.core.web.common.page.PageVo;
import com.hex.ds.hdtp.core.web.common.page.converter.IPageVoAndPageDtoConverter;
import com.hex.ds.hdtp.core.web.script.transfer.converter.IScriptConvertOptLogVoConverter;
import com.hex.ds.hdtp.core.web.script.transfer.vo.query.ScriptConvertOptLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags = "03-脚本迁移：转换清单历史")
@RequestMapping("/api/script/convert/list/his")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptConvertOptLogController {

    private final IScriptConvertOptLogService scriptConvertOptLogService;

    private final IPageVoAndPageDtoConverter pageVoAndPageDtoConverter;

    private final IScriptConvertOptLogVoConverter converter;

    @GetMapping
    @ApiOperation("脚本转换清单历史-分页查询")
    public ResponseEntity queryListByPage(ScriptConvertOptLogQueryVo scriptConvertOptLogQueryVo, PageVo pageVo) {
        log.info("进入到【ScriptConvertOptLogController.queryListByPage】方法,参数：{}" + scriptConvertOptLogQueryVo.toString());
        final PageDto pageDto = pageVoAndPageDtoConverter.toPageDto(pageVo);
        ScriptConvertOptLogRequestDto requestDto = converter.toScriptConvertListHisRequestDto(scriptConvertOptLogQueryVo);
        return ResponseEntity.ok(scriptConvertOptLogService.queryListByPage(requestDto, pageDto));
    }

    @GetMapping(value = {"/{pkId}"})
    @ApiOperation("获取转换历史清单源文件和变更文件内容")
    public ResponseEntity getContrastFileContent(@PathVariable("pkId") final String pkId) {
        log.info("进入【ScriptConvertOptLogController.scriptConvertOptLogService】方法,参数{}", pkId);
        return ResponseEntity.ok(scriptConvertOptLogService.queryById(pkId));
    }
}
